<?php

require_once("login/src/Model/Email.php");
require_once("login/src/Model/Username.php");
require_once("login/src/Model/Password.php");


class UserInfo
{
	/**
	*@var string
	**/
	private $email;
	/**
	*@var string
	**/
	private $username;
	/**
	*@var string
	**/
	private $password;
	/**
	*@var string
	**/
	private $userID;

	/**
	*@param Email
	*@param Username
	*@param Password
	*@param int
	**/
	private function __construct(Email $email, Username $username, Password $password, $userID = null)
	{
		$this->email =  $email;
		$this->username = $username;
		$this->password= $password;

		if($userID != null)
		{
			$this->userID = $userID;
		}
	}

	/**
	*@param Userinfo
	**/
	public static function SaveUserinfo(Userinfo $userinfoToSave)
	{
		$this->saveToDataBase($userinfoToSave);
	}

	/**
	*@param string
	*@param string
	*@param string
	*@return UserInfo
	**/
	public static function CreateUserInfo($email, $username, $password)
	{
		return new Userinfo(new Email($email),
			                new Username($username),
		                    Password::createWithClearTextPassword($password));
	}

	/**
	*@param int
	*@param string
	*@param string
	*@param string
	*@return UserInfo
	**/
	public static function CreateUserInfoFromDatabase($userID, $email, $username, $password)
	{
		return new Userinfo(new Email($email),
			                new Username($username),
		                    Password::createWithEncryptedPassword($password),
		                    $userID);
	}

	/**
	*@return int
	**/
	public function getUserID()
	{
		return $this->userID;
	}

	/**
	*@return string
	**/
	public function getEmail()
	{
		return $this->email->getEmail();
	}

	/**
	*@return string
	**/
	public function getUsername()
	{
		return $this->username->getUsername();
	}

	/**
	*@return string
	**/
	public function getPassword()
	{
		return $this->password->getEncryptedPassword();
	}


	/**
	*@param string
	*@param string
	*@return boolean
	**/
	public function checkForExistingUser($username, $password)
	{	
		if($password == $this->password->getEncryptedPassword() && $username == $this->username->getUsername())
		{
			return true;
		}
		return false;
	}

	/**
	*@param Userinfo
	*@return boolean
	**/
	public function checkForExistingUsername(Userinfo $userinfoToCheck)
	{
		if($this->username->getUsername() == $userinfoToCheck->getUsername())
		{
			return true;
		}
		return true;
	}

}